package com.zqt.zqt805.controller;

import com.zqt.zqt805.domain.Order;
import com.zqt.zqt805.service.OrderService;
import com.zqt.zqt805.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理接口---张淇童0805")
@RestController
@RequestMapping("/api/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "创建订单", notes = "根据用户信息创建订单")
    @PostMapping
    public AjaxResult createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return AjaxResult.success("Order created successfully", order.getOrder_id());
    }

    @ApiOperation(value = "获取订单详情", notes = "获取指定订单的详细信息")
    @GetMapping("/{order_id}")
    public AjaxResult getOrderDetails(@ApiParam(value = "订单ID", required = true) @PathVariable int order_id) {
        return AjaxResult.success(orderService.getOrderById(order_id));
    }

    @ApiOperation(value = "更新订单状态", notes = "更新订单的状态")
    @PutMapping("/{order_id}")
    public AjaxResult updateOrderStatus(@ApiParam(value = "订单ID", required = true) @PathVariable int order_id, @RequestParam String status) {
        orderService.updateOrderStatus(order_id, status);
        return AjaxResult.success("Order status updated successfully");
    }

    @ApiOperation(value = "获取所有订单", notes = "获取所有订单信息")
    @GetMapping
    public AjaxResult getAllOrders() {
        return AjaxResult.success(orderService.getAllOrders());
    }
}